package org.example.hansp.genetic.custom_generic;

import java.util.ArrayList;
import java.util.List;
@SuppressWarnings({"all"})
public class CustomExtendGeneric {
    public static void main(String[] args) {
        List<Object> list1=new ArrayList<Object>();
        List<AA> list2=new ArrayList<AA>();
        List<BB> list3=new ArrayList<BB>();
        List<CC> list4=new ArrayList<CC>();

        printCollection1(list1);
        printCollection2(list2);
        printCollection2(list3);
        printCollection2(list4);


//        printCollection2(list1);×
        printCollection2(list2);
        printCollection2(list3);
        printCollection2(list4);

        printCollection3(list1);
        printCollection3(list2);
//        printCollection3(list3); ×
//        printCollection3(list4); ×
    }
    //表示可以接受任何类型
    public static void printCollection1(List<?> list){
        for (Object obj : list) {
            System.out.println(obj);
        }
    }
    //规定了泛型的上限，只能传入AA和AA的子类
    public static void printCollection2(List<? extends AA> list){
        for (AA aa : list) {
            System.out.println(aa);
        }
    }

    //规定了泛型的下限，只能传入AA和AA的父类，不限于直接父类
    public static void printCollection3(List<? super AA> list){
        for (Object obj : list) {
            System.out.println(obj);
        }
    }
}
class AA{}
class BB extends AA{}
class CC extends BB{}